***** Reproduction Materials for "Straying from the Flock" 
***** Created by Erin Cassese
***** Created on October 29, 2019 

* use "anes_timeseries_2016_Stata13.dta"
* dataset downloaded from the ANES website on 7/5/2019

svyset [pweight=V160102], strata(V160201) psu(V160202)

******************************************************************************
* Variable Construction ******************************************************
******************************************************************************

* Respondent race 
gen white= 1 if V161310x==1
replace white=0 if V161310x!=1
replace white=. if V161310x==-9 

* Respondent gender
gen female=V161342
recode female -9=. 3=. 1=0 2=1
label define female 1 "female" 0 "male"
label values female female 

* Educational attainment & college+ dummy 
gen edu= V161270
recode edu -9=1 1/8=1 9=2 10=3 11=4 12=4 13=5 14/16=6 90=1 95=.
label define edu 1 "less than hs" 2 "hs degree"  3 "some college" 4 "AA degree" 5 "BA degree"  6 "Graduate degree" 
label values edu edu 
gen college=edu
recode college 1/4=0 5/6=1

* Income 
gen income=V161361x
recode income -9=. -8=. -5=. -2=.

* Age in years
recode V161267c -9=. -8=. 
gen age=2016-V161267c

* Marital status - 1 is married/partnered 
gen married= V161268
recode married -9=. 1=1 2=1 3=1 4=0 5=0 6=0 
 
* Children - 1 if children under 18 in the home 
gen children=V161324 
recode children -9=. 1/9=1

* South (states considered regionally South, according to the Census Bureau (Florida, Georgia, Maryland, North Carolina, South Carolina, Virginia, West Virginia, Delaware, Alabama, Kentucky, Mississippi, Tennessee, Arkansas, Louisiana, Oklahoma and Texas.)
gen south=1 if V163001a==12 | V163001a==13 | V163001a==24 | V163001a==37 | V163001a==45 | V163001a==51 |V163001a==47 | V163001a==54 | V163001a==10 | V163001a==1 | V163001a==21 | V163001a==28 | V163001a==5 | V163001a==22 | V163001a==40 | V163001a==48
replace south=0 if south==.
replace south=. if V163001a==. 

* Employed - 1 is employed full time 
gen employed=1 if V161276x==1
replace employed=0 if V161276x!=1
replace employed=. if V161276x==-9

* Biblical literalism - 1 is literal 
gen literal=V161243
recode literal -9=. -8=. 2/3=0 5=0 

* Religious intensity - composite 
gen cattend=0 if V161244==2
replace cattend=0 if V161245==5
replace cattend=1 if V161245==4
replace cattend=2 if V161245==3
replace cattend=3 if V161245==2
replace cattend=4 if V161245==1
replace cattend=5 if V161245a==2
gen relig_import=V161241
recode relig_import -9=. -8=. 2=0 
gen relig_guide=V161242
recode relig_guide -9=. -8=. -1=. 
replace relig_guide=0 if V161241==2
alpha cattend relig_import relig_guide if white==1, item std 
alpha cattend relig_import relig_guide, item std gen(relig_intensity)

* Religious affiliation 
gen reltrad=V161265x
recode reltrad -2=. 3=. 4=1 5=1 6=. 7=. 8=3
label define reltrad 1"Other Christian" 2"Evangelical" 3"Not Religious" 
label values reltrad reltrad
replace reltrad=2 if V161263==1
replace reltrad=. if  V161263==1 & V161265x==4
* Re-ordering categories for the figures 
gen rel_4graphs=reltrad
recode rel_4graphs 1=2 2=1 
label define rel_4graphs 1"Evangelical" 2"Other Christian" 3"Not Religious"
label values rel_4graphs rel_4graphs

* Partisanship 
recode V161158x -8=. -9=.
rename V161158x pid7
recode pid7 1/3=1  4=2  5/7=3, gen(pid3)
label define pid3 1"Democrats" 2"Independents" 3"Republicans"
label values pid3 pid3

* Ideology
recode V162171 -9=. -7=. -6=. 99=.
rename V162171 ideo7
replace ideo7=3 if V162171a==1
replace ideo7=4 if V162171a==3
replace ideo7=5 if V162171a==2

* Hostile sexism 
gen hostile1=V161507
recode hostile1 -9/-1=. 1=5 2=4 4=2 5=1 
gen hostile2=V161508
recode hostile2 -9/-1=. 1=5 2=4 4=2 5=1 
gen hostile3=V161509
recode hostile3 -9/-1=. 1=5 2=4 4=2 5=1 
gen hostile4=V161510 
recode hostile4 -9/-1=. 1=5 2=4 4=2 5=1 
gen hostile5=V162232
recode hostile5 -9/-6=. 1=5 2=4 4=2 5=1
gen hostile6=V162233
recode hostile6 -9/-6=. 1=5 2=4 4=2 5=1
alpha hostile1 hostile2 hostile3 hostile4 hostile5 hostile6 if white==1, item std
alpha hostile1 hostile2 hostile3 hostile4 hostile5 hostile6, item std gen(hostile)

* Feminist identification 
gen fem1=V161345
recode fem1 -5=. -9=. 1=3 3=1 
gen fem2=V161346 
recode fem2 -9/-1=. 1=5 2=4 4=2 5=1 
gen fem3=V161347
recode fem3 -9/-1=. 1=5 2=4 4=2 5=1
replace fem3=1 if V161346==5
alpha fem1 fem2 fem3 if white==1, item std 
alpha fem1 fem2 fem3, item std gen(feminist_identity)

* Anti-feminist identification 
gen anti1=V161348
recode anti1 -9/-1=. 1=5 2=4 4=2 5=1
gen anti2=V161349
recode anti2 -9/-1=. 1=5 2=4 4=2 5=1 
replace anti2=1 if V161348==5
alpha anti1 anti2 if white==1, item std 
alpha anti1 anti2, item std gen(antifeminist_identity)

* Tape reactions 
gen heard_tape=V162126
recode heard_tape 2=0 -6=. -7=. -9=.
label define heard_tape 0"No" 1"Yes"
label values heard_tape heard_tape
gen tape_matters=V162127
recode tape_matters -9/-1=. 1=5 2=4 4=2 5=1
label define tape_matters 1"Not at All" 2"A Little" 3"A Moderate Amount" 4"A Lot" 5"A great deal"
label values tape_matters tape_matters
rename V162188x trump_treats_women
recode trump_treats_women -9/-1=.
alpha tape_matters trump_treats_women if white==1, item std 
alpha tape_matters trump_treats_women, item std gen(tape_rxns)

* Candidate evaluations
gen clinton_thermpost=V162078
recode clinton_thermpost 998=. -9/-6=.
gen trump_thermpost=V162079
recode trump_thermpost 998=. -9/-6=.
gen cand_diff=trump_thermpost-clinton_thermpost
gen cand_diff2=cand_diff
replace cand_diff2=clinton_thermpost-trump_thermpost if pid3==1

* Partisan intensity
gen pid_int=pid7
recode pid_int 1=4 2=3 3=2 4=4 5=2 6=3 7=4
recode pid_int 1=. 2=1 3=2 4=3 

* Party affect 
gen demtherm=V161095
recode demtherm -99=. -89=. -88=. 
gen reptherm=V161096
recode reptherm -99=. -89=. -88=. 
gen party_diff=demtherm-reptherm
replace party_diff=reptherm-demtherm if pid3==3

* Trump vote dummy 
gen trump_votepres=1 if V162034a==2
replace trump_votepres=0 if V162034a==1 
label define trump_votepres 1"voted Trump" 0"voted Clinton" 
label values trump_votepres trump_votepres
*adding in early voters
replace trump_votepres=1 if V161027==2
replace trump_votepres=0 if V161027==1 
gen trump100=trump_votepres*100

******************************************************************************
* Figures 1-4  ***************************************************************
******************************************************************************

set scheme s2mono 

* Figure 1A

eststo: svy, subpop(white): regress hostile college income employed age married children south i.rel_4##i.female##i.pid3 relig_int literal ideo if pid3!=2
margins rel_4, by(pid3 female) atmeans post
mplotoffset, plotopts(connect(i)) offset(.05) level(84) ylabel(-.6(.2).6) ytitle("Predicted Sexism") title("A. Predicted Hostile Sexism")

* Figure 1B

eststo: svy, subpop(white): regress feminist_i college income employed age married children south i.rel_4##i.female##i.pid3 relig_int literal ideo if pid3!=2
margins rel_4, by(pid3 female) atmeans post
mplotoffset, plotopts(connect(i)) offset(.05) level(84) ylabel(-.8(.4).8) ytitle("Predicted Feminism") title("B. Predicted Feminist Identification")

* Figure 1C

eststo: svy, subpop(white): regress antifeminist_i college income employed age married children south i.rel_4##i.female##i.pid3 relig_int literal ideo if pid3!=2
margins rel_4, by(pid3 female) atmeans post
mplotoffset, plotopts(connect(i)) offset(.05) level(84) ylabel(-.6(.2).6) ytitle("Predicted Anti-Feminism") title("C. Predicted Anti-Feminist Identificaton")

* Figure 2A

eststo: svy, subpop(white): regress tape_rxn college income employed age married children south i.rel_4##i.female##i.pid3 relig_int literal ideo if pid3!=2
margins rel_4, by(pid3 female) atmeans post
mplotoffset, plotopts(connect(i)) offset(.05) level(84) ylabel(-.8(.4).8) ytitle("Predicted Reactions to the Access Hollywood Tape") title("A. Predicted Tape Reaction")

* Figure 2B

eststo: svy, subpop(white): regress cand_diff2 college income employed age married children south i.rel_4##i.female##i.pid3 relig_int literal ideo if pid3!=2
margins rel_4, by(pid3 female) atmeans post
mplotoffset, plotopts(connect(i)) offset(.05) level(84) ylabel(0(20)80) ytitle("Predicted Different in Candidate Affect") title("B. Inparty-Outparty Candidate Thermometer Ratings")

* Figure 3

graph bar (mean) trump100 if white==1 & pid3!=2 [pweight=V160102], over(female) over(rel_4) over(pid3) blabel(total, format(%9.0f)) 

* Figure 4A 

eststo: svy, subpop(white): regress pid_int college income employed age married children south i.rel_4##i.female##i.pid3 relig_int literal ideo if pid3!=2
margins rel_4, by(pid3 female) atmeans post
mplotoffset, plotopts(connect(i)) offset(.05) level(84) ylabel(1(.5)3) ytitle("Predicted Partisan Intensity") title("A. Predicted Partisan Intensity")

* Figure 4B

eststo: svy, subpop(white): regress party_diff college income employed age married children south i.rel_4##i.female##i.pid3 relig_int literal ideo if pid3!=2
margins rel_4, by(pid3 female) atmeans post
mplotoffset, plotopts(connect(i)) offset(.05) level(84) ylabel(0(20)80) ytitle("Inparty-Outparty Thermometer Ratings") title("B. Predicted Difference in Party Affect")

******************************************************************************
* Figure Contrasts ***********************************************************
******************************************************************************

* Note: The commands for the figure contrasts apply to Figures 1A-C, 2A-B, and 4A-B.
* The constrats should immediately follow each model and the associated margins command. 
* As noted in the text, you may wish to apply a more conservative standard for significance tests due to the 
* increased likelihood of a Type 1 error associated with repeated post hoc testing.
* The Bonferroni correction is: (αaltered =.05/24) = .00208333
* and αcritical = 1 – (1 – .00208333)^24 = .04882011

*Comparing female Democrats across religious categories 

*Evangelical v. Other Christian
test (1.female#1.pid3#1.rel_4=1.female#1.pid3#2.rel_4)
*Evangelical v. None
test (1.female#1.pid3#1.rel_4=1.female#1.pid3#3.rel_4)
*Other Christian v. None 
test (1.female#1.pid3#2.rel_4=1.female#1.pid3#3.rel_4)

*Comparing male Democrats across religious categories 

*Other Christian v. Evangelical
test (0.female#1.pid3#1.rel_4=0.female#1.pid3#2.rel_4)
*Evangelical v. None
test (0.female#1.pid3#1.rel_4=0.female#1.pid3#3.rel_4)
*Other Christian v None
test (0.female#1.pid3#2.rel_4=0.female#1.pid3#3.rel_4)

*Comparing male v. female Democrats within religious categories 

*Evangelical 
test (1.female#1.pid3#1.rel_4=0.female#1.pid3#1.rel_4)
*Other Christian
test (1.female#1.pid3#2.rel_4=0.female#1.pid3#2.rel_4)
*None
test (1.female#1.pid3#3.rel_4=0.female#1.pid3#3.rel_4)

*Comparing female Republicans across religious categories 

*Evangelical v. Other Christian
test (1.female#3.pid3#1.rel_4=1.female#3.pid3#2.rel_4)
*Evangelical v None
test (1.female#3.pid3#1.rel_4=1.female#3.pid3#3.rel_4)
*Other Christian v. None
test (1.female#3.pid3#2.rel_4=1.female#3.pid3#3.rel_4)

*Comparing among male Republicans across religious categories 

*Evangelical v. Other Christian
test (0.female#3.pid3#1.rel_4=0.female#3.pid3#2.rel_4)
*Evangelical v. None
test (0.female#3.pid3#1.rel_4=0.female#3.pid3#3.rel_4)
*Other Christian v None
test (0.female#3.pid3#2.rel_4=0.female#3.pid3#3.rel_4)

*Comparing male v female Republicans within religious categories 

*Evangelical
test (1.female#3.pid3#1.rel_4=0.female#3.pid3#1.rel_4)
*Other Christian 
test (1.female#3.pid3#2.rel_4=0.female#3.pid3#2.rel_4)
*None
test (1.female#3.pid3#3.rel_4=0.female#3.pid3#3.rel_4)

* Differences between Democratic and Republican women within religious categories 

*Evangelical
test (1.female#1.pid3#1.rel_4=1.female#3.pid3#1.rel_4)
*Other Christian 
test (1.female#1.pid3#2.rel_4=1.female#3.pid3#2.rel_4)
*None
test (1.female#1.pid3#3.rel_4=1.female#3.pid3#3.rel_4)

* Differences between Demoratic and Republican men within religious categories 

*Evangelical
test (0.female#1.pid3#1.rel_4=0.female#3.pid3#1.rel_4)
*Other Christian 
test (0.female#1.pid3#2.rel_4=0.female#3.pid3#2.rel_4)
*None
test (0.female#1.pid3#3.rel_4=0.female#3.pid3#3.rel_4)

******************************************************************************
* Supplemental Analysis ******************************************************
******************************************************************************

* Figure A1

graph bar (mean) trump100 if white==1 [pweight=V160102], over(female) over(rel_4) blabel(total, format(%9.0f)) 

* Figure A2

eststo: svy, subpop(white): ologit pid_int college income employed age married children south i.rel_4##i.female##i.pid3 relig_int literal ideo if pid3!=2
margins rel_4, by(pid3 female) atmeans predict(outcome(1)) 
mplotoffset, plotopts(connect(i)) offset(.05) level(84) ylabel(.1(.1).6) title("A. Predicted Probability of Outcome 1")
margins rel_4, by(pid3 female) atmeans predict(outcome(2)) 
mplotoffset, plotopts(connect(i)) offset(.05) level(84) ylabel(.1(.1).6) title("B. Predicted Probability of Outcome 2")
margins rel_4, by(pid3 female) atmeans predict(outcome(3)) 
mplotoffset, plotopts(connect(i)) offset(.05) level(84) ylabel(.1(.1).6) title("C. Predicted Probability of Outcome 3")

* Table A1

* Weighted frequencies 
svy, subpop(white): tabulate pid3 female if rel_4==1 & white==1 & pid3!=2, count
svy, subpop(white): tabulate pid3 female if rel_4==2 & white==1 & pid3!=2, count
svy, subpop(white): tabulate pid3 female if rel_4==3 & white==1 & pid3!=2, count

* Unweighted frequencies
tab pid3 female if rel_4==1 & white==1 & pid3!=2
tab pid3 female if rel_4==2 & white==1 & pid3!=2
tab pid3 female if rel_4==3 & white==1 & pid3!=2

* Table A2 - Figure 1 Models, Other Christians as baseline 

eststo clear
eststo: svy, subpop(white): regress hostile college income employed age married children south i.reltrad##i.female##i.pid3 relig_int literal ideo if pid3!=2
eststo: svy, subpop(white): regress feminist_id college income employed age married children south i.reltrad##i.female##i.pid3 relig_int literal ideo if pid3!=2
eststo: svy, subpop(white): regress antifeminist_id college income employed age married children south i.reltrad##i.female##i.pid3 relig_int literal ideo if pid3!=2
esttab using TableA2.rtf, b(2) se(2) ar2 star(+ .10 * .05 ** .01 *** .001) replace

* Table A3 - Figure 3 Models, Other Christians as baseline 

eststo clear
eststo: svy, subpop(white): regress tape_rxn college income employed age married children south i.reltrad##i.female##i.pid3 relig_int literal ideo if pid3!=2
eststo: svy, subpop(white): regress cand_diff2 college income employed age married children south i.reltrad##i.female##i.pid3 relig_int literal ideo if pid3!=2
eststo: svy, subpop(white): regress pid_int college income employed age married children south i.reltrad##i.female##i.pid3 relig_int literal ideo if pid3!=2
eststo: svy, subpop(white): regress party_diff college income employed age married children south i.reltrad##i.female##i.pid3 relig_int literal ideo if pid3!=2
eststo: svy, subpop(white): ologit pid_int college income employed age married children south i.reltrad##i.female##i.pid3 relig_int literal ideo if pid3!=2
esttab using TableA3.rtf, b(2) se(2) ar2 star(+ .10 * .05 ** .01 *** .001) replace











